<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;

/**
 * This is the model class for table "message".
 *
 * @property integer $id
 * @property string $name
 * @property string $theme
 * @property string $detail
 * @property integer $created_at
 */
class Message extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'message';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['detail'], 'string'],
            [['created_at'], 'integer'],
            [['name'], 'string', 'max' => 64],
            [['theme'], 'string', 'max' => 30],
            [['name','theme'],'required'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '模板名称',
            'theme' => '模板主题',
            'detail' => '模板详情',
            'created_at' => '创建时间',
        ];
    }

     public function behaviors()
     {
         return [
             [
                 'class' => TimestampBehavior::className(),
                 'attributes' => [
                     self::EVENT_BEFORE_INSERT => ['created_at'],
                 ],
             ],
         ];
     }

    public static function listArray()
    {
        $models = self::find()->orderBy('id asc')->all();
        $result = [];
        foreach($models as $model) {
            $result[$model->id] = $model->name;
        }
        return $result;
    }
}
